package min_path_and_road;
import java.util.*;

public class RoadPath {
	public static void show(List<List<Cell>> list){
		
		Map<Integer,Integer> map=new HashMap<Integer,Integer>( );
		int start=0;
		while(true){
		    int min_node_num=-1;
			int min_path=Integer.MAX_VALUE;
			for(int i=0;i<list.get(start).size();i++){
			Cell cell=list.get(start).get(i);	
			if((map.get(cell.getNodenum())==null)&&(cell.getWeight()<min_path)){
			    min_node_num=cell.getNodenum();
				min_path=cell.getWeight();
			  }			
			}		
			Iterator<Integer> iter=map.keySet().iterator();
			while(iter.hasNext()){
				int node_num=iter.next();
				int node_path=map.get(node_num);
			    for(int i=0;i<list.get(node_num).size();i++){
			    	Cell cell=list.get(node_num).get(i);
			    	if((map.get(cell.getNodenum())==null)&&(cell.getWeight()+node_path<min_path)){
			    		min_node_num=cell.getNodenum();
						min_path=cell.getWeight()+node_path;
			    	}
			    }			
			}	
			if(min_path<Integer.MAX_VALUE){
				 map.put(min_node_num,min_path);
			}else{
				break;
			}			
		}
		System.out.println(map);
	}
}
